package com.lovi.regExp_;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 对一个url进行解析
 * https://www.sohu.com:8080/abc/index.htm
 * a)要求得到协议是什么? http
 * b)域名是什么? www.sohu.com
 * c）端口是什么? 8080
 * d)文件名是什么? index.htm
 */
public class HW03 {
    public static void main(String[] args) {
        String content = "https://www.sohu.com:8080/abc/index.htm";
        String regStr = "^(http|https)://(([a-zA-Z]+\\.)+[a-zA-Z]+):(\\d+)/.+/([a-zA-Z]+\\.\\w+)$";
        Pattern compile = Pattern.compile(regStr);
        Matcher matcher = compile.matcher(content);
        while (matcher.find()){
            System.out.println("找到："+ matcher.group(0));
            System.out.println("协议："+ matcher.group(1));
            System.out.println("域名："+ matcher.group(2));
            System.out.println("端口："+ matcher.group(4));
            System.out.println("文件名："+ matcher.group(5));
        }

    }
}
